home *** CD-ROM | disk | FTP | other *** search
/ Aminet 38 / Aminet 38 (2000)(Schatztruhe)[!][Aug 2000].iso / Aminet / dev / c / MD5Random.readme < prev   
Encoding:
Text File  |  2000-07-01  |  2.8 KB  |  71 lines

  1. Short:    MD5-based Random Number Generator (PPC+68k)
  2. Author:   Rich Skrenta, Andreas R. Kleinert (port and sample program)
  3. Uploader: info@ar-kleinert.de
  4. Type:     dev/c
  5.  
  6.  *************************************************************************
  7.  
  8.  After becoming frustrated with the lack of a standalone, portable,
  9.  decent random number generator, I decided to make one based on a
  10.  cryptographic one-way hash function.  I chose MD5 since it is fast
  11.  and free source was readily available.  More cryptographically
  12.  secure hash functions are available (e.g. SHA-1), but for the
  13.  purposes of a rand/random/erand48 replacement, MD5 should be more
  14.  than sufficient.
  15.  
  16.  MD5 takes an arbitrary amount of input and yields a 16 byte hash.
  17.  This RNG continually MD5's a 16 byte digest, and uses the bottom N
  18.  bits as the random number yielded, where N is just large enough to
  19.  include the largest random number desired.
  20.  
  21.      To yield a random number between 0 and r:
  22.  
  23.              create mask which has enough bits to include all of r
  24.                      (for example, if r is 100, mask would be 0x7F)
  25.  
  26.              do {
  27.                      digest = MD5(digest)
  28.                      number = digest & mask
  29.              } while (number > r)
  30.  
  31.  The digest should be loaded and saved to a disk file between
  32.  invocations of a program using the RNG.
  33.  
  34.  Random functions appear after the included MD5 code.
  35.  
  36.  Send comments to:  skrenta@pbm.com (Rich Skrenta)
  37.  
  38.  *************************************************************************
  39.  
  40.  The Amiga 68k/PPC version comes with both, makefiles for 68k and PPC,
  41.  and test programs for both CPUs.
  42.  
  43.  A few changes had to be made for the Amiga port (#ifdef AMIGA) - and
  44.  since this random number generator has a "brain", the most important
  45.  change perhaps was, that the location of this brain now is "s:randseed".
  46.  
  47.  In case you want to run multiple copies of it, you'll perhaps like
  48.  to choose a different (process-dependent) name. You also could fetch
  49.  the "digest" from somewhere else (i.e. using a conventional random
  50.  number generator).
  51.  
  52.  --
  53.  ARK, 30/May/2000
  54.  
  55.  
  56. ============================= Archive contents =============================
  57.  
  58. Original  Packed Ratio    Date     Time    Name
  59. -------- ------- ----- --------- --------  -------------
  60.      459     254 44.6% 30-May-00 15:49:28 +main.c
  61.     2082    1021 50.9% 30-May-00 15:45:04 +MD5Random.readme
  62.    13836    8982 35.0% 30-May-00 15:49:30 +random
  63.     9932    3577 63.9% 30-May-00 15:39:30 +random.c
  64.    34830   16782 51.8% 30-May-00 15:50:06 +random.elf
  65.      831     383 53.9% 30-May-00 15:48:06 +random.info
  66.      233     155 33.4% 30-May-00 15:36:06 +SCOPTIONS
  67.      234     118 49.5% 30-May-00 15:23:38 +smakefile
  68.      200     103 48.5% 30-May-00 15:45:28 +smakefile68k
  69. -------- ------- ----- --------- --------
  70.    62637   31375 49.9% 31-May-100 18:45:22   9 files
  71.